package com.shrct.businessprocess.project.impl;

import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectRemainAmountCriteria;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;

public class RCProjectRemainAmountCriteriaImpl extends HQLBasedPagedQueryCriteria<RCProject> implements RCProjectRemainAmountCriteria {
  private RCEmployee sale;
  
  public RCEmployee getSale() {
    return this.sale;
  }
  
  public RCProjectRemainAmountCriteria setSale(final RCEmployee sale) {
    this.sale = sale;
    return this;			
    
  }
  
  private String projectCode;
  
  public String getProjectCode() {
    return this.projectCode;
  }
  
  public RCProjectRemainAmountCriteria setProjectCode(final String projectCode) {
    this.projectCode = projectCode;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.project.impl.RCProjectImpl this  left join  this.salers as sale ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSale()) ){
    	hql += " and ((sale.employee) = (:sale))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectCode()) ){
    	hql += " and (this.code  LIKE :projectCode)" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.code",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSale())){
    	query.setParameter("sale",getSale()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectCode())){
    	query.setParameter("projectCode",getProjectCode()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return true;
  }
  
  public RCProjectRemainAmountCriteriaImpl() {
    initOrderBys();
  }
}
